package greedy;

/**
 * 买卖股票
 */
public class TradeStocks {

    public static void main(String[] args) {
        int[] stocks = new int[] {7,1,5,3,6,4};
        int maxEarnings = getMaxEarnings(stocks);
        System.out.println(maxEarnings);
    }

    /**
     * 获取最大收益
     * @param stocks
     * @return
     */
    private static int getMaxEarnings(int[] stocks) {
        int result = 0;
        for (int i = 1; i < stocks.length; i++) {
            int earnings = stocks[i] - stocks[i-1];
            if (earnings > 0) {
                result+=earnings;
            }
        }
        return result;
    }
}
